getApp(), Page({
    data: {
        Y: "",
        M: "",
        D: "",
        num: "3",
        name: "张三",
        palette: {},
        str: "本人喝酒玩骰子，技不如人，且酒量差，实在喝不下了，心甘情愿签下此欠酒书。下次活动时，须还清所有欠酒才能上桌。",
        savePermissions: !0,
        tempPath: "",
        creating: !1,
        modalName: ""
    },
    onShow: function() {
        var t = this, e = Date.parse(new Date()), a = new Date(e), i = a.getFullYear(), n = a.getMonth() + 1 < 10 ? "0" + (a.getMonth() + 1) : a.getMonth() + 1, s = a.getDate() < 10 ? "0" + a.getDate() : a.getDate();
        t.setData({
            Y: i,
            M: n,
            D: s
        }), wx.getSetting({
            success: function(e) {
                0 == e.authSetting["scope.writePhotosAlbum"] && t.setData({
                    savePermissions: !1
                });
            }
        });
    },
    openSetting: function(t) {
        var e = this;
        wx.openSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] && e.setData({
                    savePermissions: !0
                });
            }
        });
    },
    createImg: function() {
        if (!this.data.creating) return "" == this.data.num || "" === this.data.name ? wx.showModal({
            title: "提示",
            content: "请先填写投降书信息",
            showCancel: !1
        }) : void this.setData({
            creating: !0,
            palette: {
                background: "#ffffff",
                width: "700rpx",
                height: "800rpx",
                borderRadius: "20rpx",
                views: [ {
                    type: "text",
                    text: "欠酒书",
                    css: {
                        fontSize: "50rpx",
                        top: "30rpx",
                        left: "290rpx",
                        width: "700rpx",
                        fontWeight: "bold"
                    }
                }, {
                    type: "text",
                    text: "        " + this.data.str,
                    css: {
                        fontSize: "38rpx",
                        top: "120rpx",
                        left: "40rpx",
                        width: "620rpx",
                        lineHeight: "60rpx",
                        fontWeight: "bold"
                    }
                }, {
                    type: "text",
                    text: "欠酒数量：" + this.data.num + "杯",
                    css: {
                        fontSize: "38rpx",
                        top: "400rpx",
                        left: "40rpx",
                        width: "620rpx",
                        lineHeight: "60rpx",
                        fontWeight: "bold"
                    }
                }, {
                    type: "text",
                    text: "欠酒人：" + this.data.name,
                    css: {
                        fontSize: "38rpx",
                        top: "460rpx",
                        left: "40rpx",
                        width: "620rpx",
                        lineHeight: "60rpx",
                        fontWeight: "bold"
                    }
                }, {
                    type: "text",
                    text: "日期：" + this.data.Y + "年" + this.data.M + "月" + this.data.D + "日",
                    css: {
                        fontSize: "38rpx",
                        top: "520rpx",
                        left: "40rpx",
                        width: "620rpx",
                        lineHeight: "60rpx",
                        fontWeight: "bold"
                    }
                }, {
                    type: "text",
                    text: "监制（小程序）：KTV喝酒摇骰子",
                    css: {
                        fontSize: "32rpx",
                        top: "630rpx",
                        color: "#666",
                        left: "40rpx",
                        width: "620rpx",
                        lineHeight: "60rpx",
                        fontWeight: "bold"
                    }
                } ]
            }
        });
    },
    onImgOK: function(t) {
        this.setData({
            tempPath: t.detail.path,
            creating: !1,
            modalName: "Image"
        });
    },
    onImgErr: function(t) {
        console.info(t);
    },
    numInput: function(t) {
        this.setData({
            num: t.detail.value
        });
    },
    nameInput: function(t) {
        this.setData({
            name: t.detail.value
        });
    },
    save: function() {
        var t = this;
        wx.saveImageToPhotosAlbum({
            filePath: t.data.tempPath,
            fail: function(e) {
                console.info(e), e.errMsg.indexOf("saveImageToPhotosAlbum:fail") >= 0 && t.setData({
                    savePermissions: !1
                });
            }
        });
    },
    ViewImage: function() {
        wx.previewImage({
            urls: [ this.data.tempPath ],
            current: this.data.tempPath
        });
    },
    showModal: function(t) {
        this.setData({
            modalName: t.currentTarget.dataset.target
        });
    },
    hideModal: function(t) {
        this.setData({
            modalName: null
        });
    }
});